package com.lei.zjs.web.action;

import java.io.IOException;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.activiti.engine.ProcessEngine;
import org.apache.struts2.ServletActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.lei.zjs.service.ebi.WorkordermanageService;
import com.lei.zjs.vo.Workordermanage;
import com.lei.zjs.web.action.base.BaseAction;
import com.opensymphony.xwork2.ActionContext;

/**
 * 工作单管理Action
 * @author Spinacia
 *
 */
@Controller
@Scope("prototype")
public class WorkordermanageAction extends BaseAction<Workordermanage>{

	@Resource
	private WorkordermanageService workordermanageService;
	
	
	//保存工作单数据
	public String save() throws IOException{
		String flag = "1";
		try {
			workordermanageService.save(model);
		} catch (Exception e) {
			flag = "0";
			e.printStackTrace();
		}
		HttpServletResponse response = ServletActionContext.getResponse();
		response.setContentType("text/html;charset=utf-8");
		response.getWriter().print(flag);
		return NONE;
	}
	
	//查询所有未启动的工作单(start属性为"0")
	public String list(){
		List<Workordermanage> list = workordermanageService.findListNotStart();
		ActionContext.getContext().getValueStack().set("list", list);
		return "list";
	}
	
	//启动流程
	public String start(){
		workordermanageService.start(model.getId());
		
		return "toList";
	}
}
